package com.zz.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
@Configuration
@EnableWebSocketMessageBroker
public class TeacherStompConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        // 启用简单的内存消息代理，前缀为"/topic"的消息会发送到消息代理
        registry.enableSimpleBroker("/topic");
        // // 设置应用程序目的地前缀，客户端发送消息需要以"/app"开头
        registry.setApplicationDestinationPrefixes("/app");
    }


    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // 注册STOMP端点，客户端将使用它连接到WebSocket服务器
        registry.addEndpoint("/teacher-websocket")
                .setAllowedOriginPatterns("*") // 允许所有来源
                .withSockJS(); // 启用SockJS回退选项
    }

}

